﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ExtraOpdrachten
{
    public partial class Opdracht10 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                // Maak een array aan van 6 posities
                // en voeg deze toe aan de veiwstate
                int[] results = new int[] { 0, 0, 0, 0, 0, 0 };
                ViewState.Add("Results", results);
            }
        }

        protected void btnThrow_Click(object sender, EventArgs e)
        {
            // Maak een randomizer
            Random rnd = new Random();
            // Gooi met een dobbelsteen en sla het resultaat op in de array
            int[] results = (int[])ViewState["Results"];
            int diceResult = rnd.Next(1, 7);
            results[diceResult - 1]++;
            // Toon de juiste afbeelding van een dobbelsteen
            imageDice.ImageUrl = "/Images/60px-Dice-" + diceResult.ToString() +
                ".png";
        }

        protected void btnShowResults_Click(object sender, EventArgs e)
        {
            int[] results = (int[])ViewState["Results"];
            int count = results[0] + results[1] + results[2] +
                results[3] + results[4] + results[5];
            int sum = results[0] * 1 + results[1] * 2 + 
                results[2] * 3 + results[3] * 4 + 
                results[4] * 5 + results[5] * 6;
            StringBuilder resultsTable = new StringBuilder("<table><tr><th>Ogen</th><th>Aantal</th></tr>");
            resultsTable.Append("<tr><td>1</td><td>" + results[0].ToString() + "</td></tr>");
            resultsTable.Append("<tr><td>2</td><td>" + results[1].ToString() + "</td></tr>");
            resultsTable.Append("<tr><td>3</td><td>" + results[2].ToString() + "</td></tr>");
            resultsTable.Append("<tr><td>4</td><td>" + results[3].ToString() + "</td></tr>");
            resultsTable.Append("<tr><td>5</td><td>" + results[4].ToString() + "</td></tr>");
            resultsTable.Append("<tr><td>6</td><td>" + results[5].ToString() + "</td></tr>");

            lblResult.Text = "Aantal worpen: " + count.ToString();
            lblResult.Text += "<br/>";
            lblResult.Text += "Totaal van alle worpen: " + sum.ToString();
            lblResult.Text += "<br/><br/>";
            lblResult.Text += "Overzicht worpen:";
            lblResult.Text += resultsTable.ToString();

        }
    }
}